package com.example.express.service;

import com.example.express.dto.ExpressInfoDTO;
import com.example.express.dto.LogisticsStatus;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Service
public class ExpressService {

    @Cacheable(value = "expressInfo", key = "#company + '-' + #number")
    public ExpressInfoDTO queryExpressInfo(String company, String number) {
        // 模拟调用第三方API返回的物流信息
        List<LogisticsStatus> statusList = Arrays.asList(
                new LogisticsStatus(LocalDateTime.now(), "北京", "已揽收"),
                new LogisticsStatus(LocalDateTime.now().plusHours(2), "上海", "运输中")
        );
        return new ExpressInfoDTO(company, number, statusList);
    }

    @Async
    public void asyncQueryExpressInfo(String company, String number) {
        // 异步查询逻辑
    }
}